﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace SourcesUnPacker.item
{
    public class ItemData
    {   
        // Fields
        public readonly int? _Id; // 0x10
        public readonly int? _ItemKind; // 0x18
        public readonly int? _ItemIndex; // 0x20
        public readonly string _ItemName; // 0x28
        public readonly int? _Level; // 0x30
        public readonly string _Chars; // 0x38
        public readonly int? _CharsInt; // 0x40
        public readonly string _Icon0; // 0x48
        public readonly string _Icon1; // 0x50
        public readonly int? _HpHeal; // 0x58
        public readonly int? _MpHeal; // 0x60
        public readonly string _PaintColor; // 0x68
        public readonly int? _Atk; // 0x70
        public readonly int? _Def; // 0x78
        public readonly int? _Str; // 0x80
        public readonly int? _Spr; // 0x88
        public readonly int? _Dex; // 0x90
        public readonly int? _Pow; // 0x98
        public readonly int? _EType; // 0xA0
        public readonly int? _Bio; // 0xA8
        public readonly int? _Special; // 0xB0
        public readonly int? _Weight; // 0xB8
        public readonly int? _Gold; // 0xC0
        public readonly int? _WeaponType; // 0xC8
        public readonly int? _WeaponIndex; // 0xD0
        public readonly string _Desc; // 0xD8
        public List<int> _UseRole;
        public ItemData(JArray dataArray)
        {
            _Id = dataArray[0].Type != JTokenType.Null ? Convert.ToInt32(dataArray[0]) : (int?)null;
            _ItemKind = dataArray[1].Type != JTokenType.Null ? Convert.ToInt32(dataArray[1]) : (int?)null;
            _ItemIndex = dataArray[2].Type != JTokenType.Null ? Convert.ToInt32(dataArray[2]) : (int?)null;
            _ItemName = dataArray[3].Type != JTokenType.Null ? Convert.ToString(dataArray[3]) : null;
            _Level = dataArray[4].Type != JTokenType.Null ? Convert.ToInt32(dataArray[4]) : (int?)null;
            _Chars = dataArray[5].Type != JTokenType.Null ? Convert.ToString(dataArray[5]) : null;
            _CharsInt = dataArray[6].Type != JTokenType.Null ? Convert.ToInt32(dataArray[6]) : (int?)null;
            _Icon0 = dataArray[7].Type != JTokenType.Null ? Convert.ToString(dataArray[7]) : null;
            _Icon1 = dataArray[8].Type != JTokenType.Null ? Convert.ToString(dataArray[8]) : null;
            _HpHeal = dataArray[9].Type != JTokenType.Null ? Convert.ToInt32(dataArray[9]) : (int?)null;
            _MpHeal = dataArray[10].Type != JTokenType.Null ? Convert.ToInt32(dataArray[10]) : (int?)null;
            _PaintColor = dataArray[11].Type != JTokenType.Null ? Convert.ToString(dataArray[11]) : null;
            _Atk = dataArray[12].Type != JTokenType.Null ? Convert.ToInt32(dataArray[12]) : (int?)null;
            _Def = dataArray[13].Type != JTokenType.Null ? Convert.ToInt32(dataArray[13]) : (int?)null;
            _Str = dataArray[14].Type != JTokenType.Null ? Convert.ToInt32(dataArray[14]) : (int?)null;
            _Spr = dataArray[15].Type != JTokenType.Null ? Convert.ToInt32(dataArray[15]) : (int?)null;
            _Dex = dataArray[16].Type != JTokenType.Null ? Convert.ToInt32(dataArray[16]) : (int?)null;
            _Pow = dataArray[17].Type != JTokenType.Null ? Convert.ToInt32(dataArray[17]) : (int?)null;
            _EType = dataArray[18].Type != JTokenType.Null ? Convert.ToInt32(dataArray[18]) : (int?)null;
            _Bio = dataArray[19].Type != JTokenType.Null ? Convert.ToInt32(dataArray[19]) : (int?)null;
            _Special = dataArray[20].Type != JTokenType.Null ? Convert.ToInt32(dataArray[20]) : (int?)null;
            _Weight = dataArray[21].Type != JTokenType.Null ? Convert.ToInt32(dataArray[21]) : (int?)null;
            _Gold = dataArray[22].Type != JTokenType.Null ? Convert.ToInt32(dataArray[22]) : (int?)null;
            _WeaponType = dataArray[23].Type != JTokenType.Null ? Convert.ToInt32(dataArray[23]) : (int?)null;
            _WeaponIndex = dataArray[24].Type != JTokenType.Null ? Convert.ToInt32(dataArray[24]) : (int?)null;
            _Desc = dataArray[25].Type != JTokenType.Null ? Convert.ToString(dataArray[25]) : null;
            
        }

        public void FormatUseRole()
        {
            _UseRole = new List<int>();
           var roles= _Chars.Split('|');
           for (int i = 0; i < roles.Length; i++)
           {
               // roles[i];
               if (roles[i].Equals("1"))
               {
                   _UseRole.Add(i);
               }
           }
           
        }
    }
}